

// 头像
// 淘宝会员
// 平台会员
// 入会时间
// 天猫开卡时间
// 姓名
// 性别
// 省市区 详情
// 电话







//添加或修改单条数据
exports.addUser = async (context) => {
    const cloud = context.cloud;
    const data = context.data;
    if (!!data.id) {
        const result = await cloud.db.collection('users').replaceOne(
            {
                _id: data.id
            },
            data
        );
        return result;
    } else {
        const result = cloud.db.collection('users').insertOne(data)
        return result;
    }
};
//添加多条数据
exports.addUsers = async function (context) {
    const cloud = context.cloud;
    const result = await cloud.db.collection('users').insertMany([
        {
            name: 'tom',
            age: 1
        },
        {
            name: 'jerry',
            age: 2
        }
    ]);
    return result;
}
exports.getItem = async function (context) {
    const cloud = context.cloud;
    let data = context.data;
    const result = await cloud.db.collection('users').find({ _id: data.id }, {
        sort: { _id: -1 },
    })
    return {result,context};
}
exports.deleteItemById = async function (context) {
    const cloud = context.cloud;
    const data = context.data;
    cloud.db.collection('users').deleteMany({ _id: data.id }).then((res) => {
        return res;
    })
}

exports.main = async function (context) {

    return context;
}